package com.xzy.ec.controller;



import com.xzy.ec.entity.*;
import com.xzy.ec.result.R;
import com.xzy.ec.service.IOmsOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xzy
 * @since 2022-06-05
 */
@RestController
@RequestMapping("/admin/core/omsOrder")
@Api(value = "OmsOrderController",tags = "订单控制器")
public class OmsOrderController {


    @Resource(name = "OrderService")
    IOmsOrderService service;

    //展示所有订单
    @GetMapping("/list")
    @ApiOperation(value = "list",notes = "展示所有订单")
    public R list(){
        return R.ok().data("orderVOList", service.getList());
    }

    //修改订单状态
    @PostMapping("/updata/state/{oid}/{status}")
    @ApiOperation(value = "updataStatus",notes = "修改订单状态")
    public R updataStatus(@ApiParam(value = "订单号", required = true)@PathVariable Integer oid,
                         @ApiParam(value = "状态", required = true)@PathVariable Integer status){
        boolean flag = service.updataStatus(oid, status);
        if (flag)return R.ok().data("flag", flag);
        return R.error().data("flag", flag);
    }

    //根据单号获取收获地址
    @PostMapping("/getDeliveryAddr/{oid}/")
    @ApiOperation(value = "getDeliveryAddr",notes = "获取订单地址")
    public R getDeliveryAddr(@ApiParam(value = "订单号", required = true)@PathVariable Integer oid){
        String deliveryAddr=service.getDeliveryAddr(oid);
        return R.ok().data("deliveryAddr", deliveryAddr);
    }
    //单号获取用户
    @PostMapping("/getUser/{oid}/")
    @ApiOperation(value = "getUser",notes = "获取订单用户")
    public R getUser(@ApiParam(value = "订单号", required = true)@PathVariable Integer oid){
        UserVO user =service.getUser(oid);
        return R.ok().data("user", user);
    }
    //单号获取商品
    @PostMapping("/getGoodSpecs/{oid}/")
    @ApiOperation(value = "getGoodSpecs",notes = "获取订单商品")
    public R getGoodSpecs(@ApiParam(value = "订单号", required = true)@PathVariable Integer oid){
        GoodSpecsVO goodSpecs =service.getGoodSpecsVO(oid);
        return R.ok().data("goodSpecs", goodSpecs);
    }
    //下单
    @PostMapping("/placeOrder/{gid}/{uid}/{num}/")
    @ApiOperation(value = "placeOrder",notes = "下单")
    public R  addOrder(@ApiParam(value = "用户id", required = true)@PathVariable Integer uid,
                         @ApiParam(value = "商品id", required = true)@PathVariable Integer gid,
                         @ApiParam(value = "下单数量", required = true)@PathVariable Integer num){
        boolean flag=service.placeOrder(uid,gid,num);
        if (flag)return R.ok().data("flag", flag);
        return R.error().data("flag", flag);
    }
    //更新订单
    @PostMapping("/updateOrder/{oid}/")
    @ApiOperation(value = "updateOrder",notes = "修改订单")
    public R addOrder(@ApiParam(value = "订单id", required = true)@PathVariable Integer oid,
                      @ApiParam(value = "修改后的订单", required = true) OrderVO orderVO){
        boolean flag=service.updateOrder(oid,orderVO);
        if (flag)return R.ok().data("flag", flag);
        return R.error().data("flag", flag);
    }
    //删除订单
    @DeleteMapping("/deleteOrder/{oid}")
    @ApiOperation(value = "deleteOrder",notes = "删除订单")
    public R deleteOrder(@ApiParam(value = "订单id", required = true)@PathVariable Integer oid){
        boolean flag=service.deleteOrder(oid);
        if (flag)return R.ok().data("flag", flag);
        return R.error().data("flag", flag);
    }
    //查询订单
    @PostMapping("/ListByUid/{uid}")
    @ApiOperation(value = "ListByUid",notes = "uid查询订单")
    public R listByUid(@ApiParam(value = "用户id", required = true)@PathVariable Integer uid){
        List<OrderVO> orderVOList=service.listByUid(uid);
        if (null!=orderVOList)return R.ok().data("orderVOList", orderVOList);
        return R.error();
        //d
    }

    //获取订单信息d
    @PostMapping("/getOrderVO/{oid}")
    @ApiOperation(value = "getOrderVO",notes = "oid查询订单")
    public R getOrderVO(@ApiParam(value = "订单id", required = true)@PathVariable Integer oid){
        OrderVOo orderVOo=service.getOrderVO(oid);
        if (null!=orderVOo)return R.ok().data("orderVOo", orderVOo);
        return R.error();
    }

}

